package org.swust.sysmonitorapp.service;

import org.springframework.stereotype.Service;

import java.util.concurrent.ConcurrentLinkedQueue;

@Service
public class AmqpMessageService {
    private final ConcurrentLinkedQueue<String> lastMessages = new ConcurrentLinkedQueue<>();

    public void process(String message) {
        // 保存最后50条消息用于展示
        if(lastMessages.size() > 50) {
            lastMessages.poll();
        }
        lastMessages.offer(message);
    }

    public ConcurrentLinkedQueue<String> getMessages() {
        return new ConcurrentLinkedQueue<>(lastMessages);
    }
}
